package product;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.GridBagLayout;

import javax.swing.JLabel;

import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Dimension;
import java.util.HashMap;

import javax.swing.border.BevelBorder;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JTextArea;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

public class HolyReason2 extends JFrame {

	HashMap<String, MemberData> holy;
	MemberHoly my;

	private JPanel contentPane;
	private JPanel panel;
	private JButton button;
	private JPanel panel_1;
	private JLabel label;
	private JLabel label_1;
	private JLabel label_2;
	private JScrollPane scrollPane;
	private JLabel label_3;
	private JScrollPane scrollPane_1;
	private JLabel label_4;
	private JScrollPane scrollPane_2;
	private JTextArea accident;
	private JTextArea reason;
	private JTextArea result;

	//	/**
	//	 * Launch the application.
	//	 */
	//	public static void main(String[] args) {
	//		EventQueue.invokeLater(new Runnable() {
	//			public void run() {
	//				try {
	//					HolyReason2 frame = new HolyReason2();
	//					frame.setVisible(true);
	//				} catch (Exception e) {
	//					e.printStackTrace();
	//				}
	//			}
	//		});
	//	}

	/**
	 * Create the frame.
	 */
	public HolyReason2(HashMap<String, MemberData> holy, MemberHoly mh) {

		this.holy = holy;
		this.my = mh;

		setTitle("사유서 수정창");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		contentPane.add(getPanel(), BorderLayout.SOUTH);
		contentPane.add(getPanel_1(), BorderLayout.CENTER);

		String[] hyrn = my.Reason.split("%");
		accident.setText(hyrn[0]);
		reason.setText(hyrn[1]);
		result.setText(hyrn[2]);

	}
	private JPanel getPanel() {
		if (panel == null) {
			panel = new JPanel();
			panel.setPreferredSize(new Dimension(10, 30));
			panel.add(getButton());
		}
		return panel;
	}
	private JButton getButton() {
		if (button == null) {
			button = new JButton("수정");
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {

					try{
						int row = my.ResultTable.getSelectedRow();
						String hk = (String)my.model.getValueAt(row, 0); // 날자


						int  yn =JOptionPane.showConfirmDialog(null, "정말 수정 하시겠습니까? ");
						if(yn == JOptionPane.YES_OPTION){
							MemberData data = new MemberData(my.userID.getText(),hk,"4", "심사중", 
									accident.getText()+"%"
											+ reason.getText()+"%"
											+ result.getText());
							holy.put("["+my.userID.getText()+"]"+hk, data);

//							my.oos = new ObjectOutputStream(new FileOutputStream("/MemberManage/Holy"));
//							my.oos.writeObject(my.pm.holy);
//							my.oos.close();

							my.model.setValueAt((String)"4",row, 2);
							my.model.setValueAt("심사중", row, 3);

							JOptionPane.showMessageDialog(null, "수정되었습니다. ");
						}else{
							JOptionPane.showMessageDialog(null, "취소되었습니다. ");
						}

					}catch(Exception ee){
						JOptionPane.showMessageDialog(null, "입력형식이 잘못되었습니다. ");
					}


				}
			});
		}
		return button;
	}
	private JPanel getPanel_1() {
		if (panel_1 == null) {
			panel_1 = new JPanel();
			GridBagLayout gbl_panel_1 = new GridBagLayout();
			gbl_panel_1.columnWidths = new int[]{0, 0, 0};
			gbl_panel_1.rowHeights = new int[]{0, 0, 0, 0, 0};
			gbl_panel_1.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
			gbl_panel_1.rowWeights = new double[]{0.0, 1.0, 1.0, 1.0, Double.MIN_VALUE};
			panel_1.setLayout(gbl_panel_1);
			GridBagConstraints gbc_label = new GridBagConstraints();
			gbc_label.fill = GridBagConstraints.BOTH;
			gbc_label.insets = new Insets(0, 0, 5, 5);
			gbc_label.gridx = 0;
			gbc_label.gridy = 0;
			panel_1.add(getLabel(), gbc_label);
			GridBagConstraints gbc_label_1 = new GridBagConstraints();
			gbc_label_1.insets = new Insets(0, 0, 5, 0);
			gbc_label_1.gridx = 1;
			gbc_label_1.gridy = 0;
			panel_1.add(getLabel_1(), gbc_label_1);
			GridBagConstraints gbc_label_2 = new GridBagConstraints();
			gbc_label_2.fill = GridBagConstraints.VERTICAL;
			gbc_label_2.insets = new Insets(0, 0, 5, 5);
			gbc_label_2.gridx = 0;
			gbc_label_2.gridy = 1;
			panel_1.add(getLabel_2(), gbc_label_2);
			GridBagConstraints gbc_scrollPane = new GridBagConstraints();
			gbc_scrollPane.fill = GridBagConstraints.BOTH;
			gbc_scrollPane.insets = new Insets(0, 0, 5, 0);
			gbc_scrollPane.gridx = 1;
			gbc_scrollPane.gridy = 1;
			panel_1.add(getScrollPane(), gbc_scrollPane);
			GridBagConstraints gbc_label_3 = new GridBagConstraints();
			gbc_label_3.fill = GridBagConstraints.BOTH;
			gbc_label_3.insets = new Insets(0, 0, 5, 5);
			gbc_label_3.gridx = 0;
			gbc_label_3.gridy = 2;
			panel_1.add(getLabel_3(), gbc_label_3);
			GridBagConstraints gbc_scrollPane_1 = new GridBagConstraints();
			gbc_scrollPane_1.fill = GridBagConstraints.BOTH;
			gbc_scrollPane_1.insets = new Insets(0, 0, 5, 0);
			gbc_scrollPane_1.gridx = 1;
			gbc_scrollPane_1.gridy = 2;
			panel_1.add(getScrollPane_1(), gbc_scrollPane_1);
			GridBagConstraints gbc_label_4 = new GridBagConstraints();
			gbc_label_4.fill = GridBagConstraints.BOTH;
			gbc_label_4.insets = new Insets(0, 0, 0, 5);
			gbc_label_4.gridx = 0;
			gbc_label_4.gridy = 3;
			panel_1.add(getLabel_4(), gbc_label_4);
			GridBagConstraints gbc_scrollPane_2 = new GridBagConstraints();
			gbc_scrollPane_2.fill = GridBagConstraints.BOTH;
			gbc_scrollPane_2.gridx = 1;
			gbc_scrollPane_2.gridy = 3;
			panel_1.add(getScrollPane_2(), gbc_scrollPane_2);
		}
		return panel_1;
	}
	private JLabel getLabel() {
		if (label == null) {
			label = new JLabel("");
			label.setPreferredSize(new Dimension(80, 0));
		}
		return label;
	}
	private JLabel getLabel_1() {
		if (label_1 == null) {
			label_1 = new JLabel("내용");
		}
		return label_1;
	}
	private JLabel getLabel_2() {
		if (label_2 == null) {
			label_2 = new JLabel("사고");
			label_2.setPreferredSize(new Dimension(80, 0));
			label_2.setHorizontalAlignment(SwingConstants.CENTER);
			label_2.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		}
		return label_2;
	}
	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setPreferredSize(new Dimension(80, 100));
			scrollPane.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
			scrollPane.setViewportView(getAccident());
		}
		return scrollPane;
	}
	private JLabel getLabel_3() {
		if (label_3 == null) {
			label_3 = new JLabel("사유");
			label_3.setPreferredSize(new Dimension(0, 60));
			label_3.setHorizontalAlignment(SwingConstants.CENTER);
			label_3.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		}
		return label_3;
	}
	private JScrollPane getScrollPane_1() {
		if (scrollPane_1 == null) {
			scrollPane_1 = new JScrollPane();
			scrollPane_1.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
			scrollPane_1.setViewportView(getReason());
		}
		return scrollPane_1;
	}
	private JLabel getLabel_4() {
		if (label_4 == null) {
			label_4 = new JLabel("처리");
			label_4.setPreferredSize(new Dimension(0, 60));
			label_4.setHorizontalAlignment(SwingConstants.CENTER);
			label_4.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		}
		return label_4;
	}
	private JScrollPane getScrollPane_2() {
		if (scrollPane_2 == null) {
			scrollPane_2 = new JScrollPane();
			scrollPane_2.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
			scrollPane_2.setViewportView(getResult());
		}
		return scrollPane_2;
	}
	private JTextArea getAccident() {
		if (accident == null) {
			accident = new JTextArea();
		}
		return accident;
	}
	private JTextArea getReason() {
		if (reason == null) {
			reason = new JTextArea();
		}
		return reason;
	}
	private JTextArea getResult() {
		if (result == null) {
			result = new JTextArea();
		}
		return result;
	}
}
